package com.jiantong.work.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * Created by maowenjie on 2017/4/17.
 *
 */
@Data
public class VaccinePurchaseRecord implements Serializable{
    private static final ObjectMapper objectMapper = JsonMapper.nonEmptyMapper().getMapper();
    private static final long serialVersionUID = 8219579043759590899L;
    /**
     *
     */
    private Long id;
    /**
     *'单据编号'
     */
    private String number;
    /**
     *'养殖场id'
     */
    private Long  breedFactoryId;
    /**
     *'养殖场名称'
     */
    private String breedFactoryName;

    /**
     * 购买人
     */
    private String operator;

    /**
     *'购入日期、进场日期'
     */
    private Date date;
    /**
     * 养殖品种
     */
    private Integer breedType;
    /**
     *'采购名称'
     */
    private Integer productName;
    /**
     *'其他名称'
     */
    private String otherName;
    /**
     * 兽药规格
     */
    private String standard;

    /**
     * 批准文号
     */
    private String approvalNumber;
    /**
     *'数量'
     */
    private Integer quantity;
    /**
     *'单价'
     */
    private Float price;
    /**
     *'总价'
     */
    private Float totalPrice;
    /**
     * 供应商兽药经营许可证号
     */
    private String dealerNumber;
    /**
     *'经销商名称'
     */
    private String dealerName;
    /**
     * 生产厂家／GMP证书号
     */
    private String manufacturerFactory;
    /**
     *'生产厂家照片'
     */
    @JsonIgnore
    private String manufacturerPhoto;
    /**
     * 生产厂家照片-------不存入数据库
     */
    private Map<String,Map<String,String>>manufacturer;
    /**
     * 批号
     */
    private String batch;
    /**
     * 有效日期
     */
    private Date effectiveDate;
    /**
     *'批号照片,'
     */
    @JsonIgnore
    private String batchNumberPhoto;
    /**
     * 批号照片------不存入数据库
     */
    private Map<String,Map<String,String>> batchNumber;

    /**
     *'状态，0:未提交 1：生效 '
     */
    private Integer status;
    /**
     * 备注
     */
    private String remark;
    /**
     *'1：正常，-1：删除'
     */
    private Integer deleteFlag;
    /**
     *
     */
    private Date createdAt;
    /**
     *
     */
    private Date updatedAt;

    private void setManufacturerPhoto(String manufacturerPhoto)throws Exception{
        this.manufacturerPhoto=manufacturerPhoto;
        if(Strings.isNullOrEmpty(manufacturerPhoto)){
            this.manufacturer=  Maps.newHashMap();
        }else {
            this.manufacturer = objectMapper.readValue(manufacturerPhoto, new TypeReference<Map<String,Map<String,String>>>(){});
        }
    }
    private void setManufacturer(Map<String,Map<String,String>> manufacturer){
        this.manufacturer=manufacturer;
        if(manufacturer==null ||manufacturer.isEmpty()){
            this.manufacturerPhoto=null;
        }else{
            try{
                this.manufacturerPhoto = objectMapper.writeValueAsString(manufacturer);
            }catch (Exception e){

            }
        }
    }

    private void setBatchNumberPhoto(String batchNumberPhoto)throws Exception{
        this.batchNumberPhoto=batchNumberPhoto;
        if(Strings.isNullOrEmpty(batchNumberPhoto)){
            this.batchNumber=  Maps.newHashMap();
        }else {
            this.batchNumber = objectMapper.readValue(batchNumberPhoto, new TypeReference<Map<String,Map<String,String>>>(){});
        }
    }
    private void setBatchNumber(Map<String,Map<String,String>> batchNumber){
        this.batchNumber=batchNumber;
        if(batchNumber==null ||batchNumber.isEmpty()){
            this.batchNumberPhoto=null;
        }else{
            try{
                this.batchNumberPhoto = objectMapper.writeValueAsString(batchNumber);
            }catch (Exception e){

            }
        }
    }

}
